package com.zhangxin.easyexcelutil.common;

import java.io.Serializable;
import java.util.List;

/**
 * Created by zhangxin on 2021/1/30.
 */
public class Result implements Serializable {

    private static final long serialVersionUID = 3173262623444126052L;
    private List data;
    private boolean flag;
    private int code;
    private String error;

    public Result() {
    }

    public Result(List data) {
        this.data = data;
        this.flag = true;
    }

    public Result(List data, String error) {
        this.flag = false;
        this.data = data;
        this.error = error;
    }

    public Result(List data, int code, String error) {
        this.flag = false;
        this.data = data;
        this.code = code;
        this.error = error;
    }

    public static Result success() {
        Result result = new Result();
        result.setFlag(true);
        return result;
    }

    public static Result fail(String error) {
        Result result = new Result();
        result.setFlag(false);
        result.setError(error);
        return result;
    }

    public static Result fail(int code, String error) {
        Result result = new Result();
        result.setFlag(false);
        result.setCode(code);
        result.setError(error);
        return result;
    }

    public boolean ok() {
        return this.flag;
    }

    public List getData() {
        return this.data;
    }

    public void setData(List data) {
        this.data = data;
    }

    public boolean isFlag() {
        return this.flag;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    public int getCode() {
        return this.code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getError() {
        return this.error;
    }

    public void setError(String error) {
        this.error = error;
    }
}
